<%@ page import="com.biz.conf.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分组标签管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resources/plugins/h+/css/TreeGrid.css"/>
    <style>
.setimgsize{
    height: 60px;
}
    </style>
</head>

<body class="gray-bg">


<div class="wrapper wrapper-content  animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="toolbar" style="padding-bottom: 10px">
                <div id="toolbar">
                   <%-- <shiro:hasPermission name="org:add">--%>
                        <button id="btn_add" class="btn btn-primary"><i class="fa fa-plus-circle"></i>&nbsp;新增商品属性</button>
                    <%--</shiro:hasPermission>--%>
                    <%--<button id="bbtn_addtn_del" class="btn btn-w-s btn-danger"><i class="fa fa-times-circle"></i>&nbsp;批量删除</button>
                    <button id="button" class="btn btn-primary " ><i class="fa fa-check-circle"></i>&nbsp;获取选中</button>
                    <button id="btn_getCheck" class="btn btn-primary " ><i class="fa fa-check-square"></i>&nbsp;获取选中ChekBox</button>--%>
                </div>
            </div>
            <span id="spancc" class="spancc"></span>
            <div class="row">
                <%--<div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-2"><input placeholder="岗位名称" id="q_org_name" class="form-control" ></div>
                            <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                        </div>
                    </div>
                </div>--%>
            </div>
            <div id="orgTreeGrid"></div>
        </div>
    </div>

</div>
<div id="mask" class="mask"></div>
<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>


<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/h+/js/TreeGrid.js"></script>
<style>
</style>
<script>

</script>
<script>
    var picPath='<%=Global.getConfig("OSSURL")%>';

    var treeGrid;
    var orgData=[];
    var config = '';
    /**初始化方法*/
    $(function () {
        loadOrgs();
    });


    /**当前选中的角色树ID*/
    var nowSelectRoleNode="";


    /**加载组织架构*/
    function loadOrgs() {
        $("#orgTreeGrid").html("");
        $.ajax({
            url: '${pageContext.request.contextPath}/property/getAllStandardList.ac',// 跳转到 action
            data: {},
            type: 'post',
            cache: false,
            async: false,
            dataType: 'json',
            success: function (data) {
                data=eval('(' + data + ')');

                config = {
                    id: "tg1",
                    width: "800",
                    renderTo: "orgTreeGrid",
                    headerAlign: "left",
                    headerHeight: "36",
                    dataAlign: "left",
                    indentation: "20",
                    folderOpenIcon: "${pageContext.request.contextPath}/resources/plugins/h+/img/folderOpen.gif",
                    folderCloseIcon: "${pageContext.request.contextPath}/resources/plugins/h+/img/folderClose.gif",
                    defaultLeafIcon: "noImg",  //${pageContext.request.contextPath}/resources/plugins/h+/img/defaultLeaf.gif
                    hoverRowBackground: "false",
                    folderColumnIndex: "0",
                    /*itemClick: "itemClickEvent",*/
                    columns:[
                        /*{headerText: "", headerAlign: "center", dataAlign: "center", width: "20", handler: "customCheckBox"},*/
                        {headerText: "名称", dataField: "name", headerAlign: "center", dataAlign: "center", width: "",handler: "nameText"},
                        {headerText: "来源", dataField: "type", headerAlign: "center", dataAlign: "center", width: "", handler: "typeSource"},
                        {headerText: "操作", headerAlign: "center", dataAlign: "center", width: "", handler: "operation"}
                    ],
                    data:data
                };

                //console.log(config);
            },
            error: function () {
                parent.layer.msg('加载组织架构列表失败！');
            }
        });

        //创建一个组件对象
        treeGrid = new TreeGrid(config);
        treeGrid.show();
        $(".TreeGrid tr").click(function(){
            $(".TreeGrid tr").css("background-color","inherit");
            $(this).css("background-color","#d0e9c6");
        });
    }

    /*
     单击数据行后触发该事件
     id：行的id
     index：行的索引。
     data：json格式的行数据对象。
     */
    function itemClickEvent(id, index, data){
        alert(id + ", " + index + ", " + TreeGrid.json2str(data));
    }

    /*
     通过指定的方法来自定义栏数据
     */
    function customCheckBox(row, col){
        return "<input type='checkbox'>";
    }

    function customOrgName(row, col){
        var name = row[col.dataField] || "";
        var url=picPath+name;
        return '<img src="'+url+'" class="setimgsize">';
    }

    //typeSource
    function typeSource(row, col){
        if(row.type=="0"){
            return "后台品牌店";
        }else{
            return "供应链数据";
        }
    }

    //nameText
    function nameText(row, col)
    {
        return "&nbsp;&nbsp;"+row.name;
    }


    //操作
    function operation(row, col){
        var id = row.id;
        var pid=row.pid;
            return '<a style="color:#337ab7;text-decoration:none" href="javascript:void(0)" onclick="showPopupForEdit(\''+id+'\',\''+pid+'\')" >编辑</a> &nbsp;&nbsp;'+
                    '<a style="color:#337ab7;text-decoration:none" href="javascript:void(0)" onclick="delOrg(\''+id+'\',\''+pid+'\')" >作废</a>';
    }

    /*
     展开、关闭所有节点。
     isOpen=Y表示展开，isOpen=N表示关闭
     */
    function expandAll(isOpen){
        treeGrid.expandAll(isOpen);
    }

    /*
     取得当前选中的行，方法返回TreeGridItem对象
     */
    function selectedItem(){
        var treeGridItem = treeGrid.getSelectedItem();
        if(treeGridItem!=null){
            //获取数据行属性值
            //alert(treeGridItem.id + ", " + treeGridItem.index + ", " + treeGridItem.data.name);

            //获取父数据行
            var parent = treeGridItem.getParent();
            if(parent!=null){
                //jQuery("#currentRow").val(parent.data.name);
            }

            //获取子数据行集
            var children = treeGridItem.getChildren();
            if(children!=null && children.length>0){
                jQuery("#currentRow").val(children[0].data.name);
            }
        }
    }
    /*******************************************************工具栏*******************************************************/
    /**新增按钮事件*/
        //新增分组
    $("#btn_add").click(function(){

        showPopup(0,'');
    });
    function showPopup(type,id){
        //自定页
        layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['500px', '400px'],
            content: '${pageContext.request.contextPath}/property/toStandardDetail.ac?type='+type+'&id='+id,
            success: function(layero, index){
                loadOrgs();
            },
            cancel: function(index){
                loadOrgs();
                return true;
            },
            close  : function(index){
                loadOrgs();
            },
            end : function(index){
                loadOrgs();
            }
        });
    }
    function showPopupForEdit(id){
            showPopup(1,id);
    }

    /**岗位删除操作*/
    function delOrg(id,pid){
        swal({
            title: "您确定要作废这些信息吗",
            text: "作废后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "作废",
            cancelButtonText:"取消",
            closeOnConfirm: true
        }, function () {
            $.ajax({
                url: '${pageContext.request.contextPath}/property/delStandard.ac?id='+id+'&pid='+pid,
                data: {},
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    if(data.success==true)
                    {
                        parent.layer.msg('作废成功');
                        loadOrgs();
                    }else{
                        parent.layer.msg(data);
                    }
                },
                error: function () {
                    parent.layer.msg('作废失败！');
                }
            });

        });
    }

</script>
</body>

</html>